package TestDemo4;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2024-06-09
 * Time: 18:42
 */








/*class Person{
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }



   *//*  @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }*//*

   @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
public class Test {
    public static void main(String[] args) {
        Person person1 = new Person("张三",12);
        //System.out.println(person1);

        Person person2 = new Person("张三",12);
        //System.out.println(person2);

        *//*System.out.println(person1 == person2);
        System.out.println("=============");
        System.out.println(person1.equals(person2));
        System.out.println("=============");

        Person person3 = person2;
        System.out.println(person3.equals(person2));*//*

        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());

    }
}*/





/*
class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name,int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Student o) {
        if(this.age > o.age){
            return 1;
        } else if (this.age > o.age) {
            return -1;
        }else {
            return 0;
        }
    }
}

public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("张三",12);
        Student student2 = new Student("王五",5);
        System.out.println(student1.compareTo(student2));
    }
}*/


/*
class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}

public class Test {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("张三",10);
        students[1] = new Student("王五",12);
        students[2] = new Student("李四",5);

        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}*/






/*
class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if(this.age > o.age){
            return 1;
        } else if (this.age < o.age) {
            return -1;
        }else {
            return 0;
        }
    }
}

public class Test {

    public static void bubbleSort(Comparable[] comparable){
        for (int i = 0; i < comparable.length - 1; i++) {
            for (int j = 0; j < comparable.length - 1 - i; j++) {
                if(comparable[j].compareTo(comparable[j + 1]) > 0){
                    Comparable tmp = comparable[j];
                    comparable[j] = comparable[j + 1];
                    comparable[j + 1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] =  new Student("张三",10);
        students[1] = new Student("李武",14);
        students[2] = new Student("王五",1);
        bubbleSort(students);
        System.out.println(Arrays.toString(students));
    }
}*/




class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class NameComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void main(String[] args) {
        Student student = new Student("张三",12);
        Student student1 = new Student("王五",17);

        AgeComparator ageComparator = new AgeComparator();
        ageComparator.compare(student,student1);
    }
}